<?php

$paginator->options(array('url' => $this->passedArgs));
if(!isset($norace))
    $norace = false;
if(!isset($nocoach))
    $nocoach = false;
?>
<div class="teams">
<h2><?php echo $title?></h2>
<p><?php echo $paginator->counter(array('format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true))); ?></p>
<table cellpadding = "0" cellspacing = "0">
<tr>
	<th><?php echo $paginator->sort('Name', 'Team.strName');?></th>
	<?php if(!$nocoach) { ?>
	<th><?php echo $paginator->sort('Coach', 'Team.idCoach');?></th>
	<?php } if(!$norace) { ?>
	<th><?php echo $paginator->sort('Race', 'Team.idRaces');?></th>
	<?php } ?>
	<th><?php echo $paginator->sort('Value', 'Team.iValue');?></th>
	<th><?php echo $paginator->sort('G', 'StatisticsTeam.iMatchPlayed');?></th>
	<th><?php echo $paginator->sort('W', 'StatisticsTeam.iWins');?></th>
	<th><?php echo $paginator->sort('D', 'StatisticsTeam.iDraws');?></th>
	<th><?php echo $paginator->sort('L', 'StatisticsTeam.iLoss');?></th>
	<th><?php echo $paginator->sort('Gp', 'StatisticsTeam.iMatchPlayed');?></th>
	<th><?php echo $paginator->sort('%W', 'StatisticsTeam.fPerWins');?></th>
	<th><?php echo $paginator->sort('%D', 'StatisticsTeam.fPerDraws');?></th>
	<th><?php echo $paginator->sort('%L', 'StatisticsTeam.fPerLoss');?></th>
	<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($teams as $team):
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
?>
	<tr<?php echo $class;?>>
		<td><?php echo $team['Team']['strName']; ?></td>
		<?php if(!$nocoach) { ?>
		<td><?php echo $html->link($team['Coach']['strName'], array('controller' => 'coaches', 'action' => 'view', $team['Coach']['ID'])); ?></td>
		<?php } if(!$norace) { ?>
		<td><?php echo $html->link($team['Race']['LocalizedString'][$locale], array('controller' => 'races', 'action' => 'view', $team['Race']['ID'])); ?></td>
		<?php } ?>
		<td><?php echo $team['Team']['iValue']; ?></td>
		<td><?php echo $team['StatisticsTeam']['iMatchPlayed']; ?></td>
		<td><?php echo $team['StatisticsTeam']['iWins']; ?></td>
		<td><?php echo $team['StatisticsTeam']['iDraws']; ?></td>
		<td><?php echo $team['StatisticsTeam']['iLoss']; ?></td>
		<td><?php echo $team['StatisticsTeam']['iMatch']; ?></td>
		<td><?php echo $number->toPercentage($team['StatisticsTeam']['fPerWins']); ?></td>
		<td><?php echo $number->toPercentage($team['StatisticsTeam']['fPerDraws']); ?></td>
		<td><?php echo $number->toPercentage($team['StatisticsTeam']['fPerLoss']); ?></td>
		<td class="actions">
			<?php echo $html->link(__('View', true), array('controller' => 'teams', 'action' => 'view', $team['Team']['ID'])); ?>
			<?php echo $html->link(__('Edit', true), array('controller' => 'teams', 'action' => 'edit', $team['Team']['ID'])); ?>
			<?php echo $html->link(__('Delete', true), array('controller' => 'teams', 'action' => 'delete', $team['Team']['ID']), null, sprintf(__('Are you sure you want to delete # %s?', true), $team['Team']['ID'])); ?>
		</td>
	</tr>
<?php endforeach; ?>
</table>
<div class="paging">
	<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
 | 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
</div>
</div>
